class QueueUsingStack:
    def __init__(self):
        self.enqueue_stack = []
        self.dequeue_stack = []

    def enqueue(self, item):
        self.enqueue_stack.append(item)

    def dequeue(self):
        if len(self.dequeue_stack) == 0:
            while len(self.enqueue_stack) > 0:
                self.dequeue_stack.append(self.enqueue_stack.pop())
        return self.dequeue_stack.pop()


class StackUsingQueue:
    def __init__(self):
        self.primary_queue = []
        self.backup_queue = []

    def push(self, item):
        self.primary_queue.append(item)

    def pop(self):
        while len(self.primary_queue) > 1:
            self.backup_queue.append(self.primary_queue.pop(0))
        result = self.primary_queue.pop(0)
        self.primary_queue, self.backup_queue = self.backup_queue, self.primary_queue
        return result
